package com.xinyuan.trade.Fragment;

import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xinyuan.trade.R;
import com.xinyuan.trade.Adapter.TypeAdapter;

/**
 * 分类
 * 
 * @author daiy
 * 
 */
public class TypeFragment extends BaseFragment {

	private Resources resources;
	private RelativeLayout layout_top;
	private TextView tv_top;
	private GridView gridview;

	@Override
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.fragment_type, container, false);

		resources = getResources();
		initView(v);
		return v;
	}

	private void initView(View v) {
		layout_top = (RelativeLayout) v.findViewById(R.id.layout_top);
		uiAdapter.setMargin(layout_top, LayoutParams.MATCH_PARENT, 60, 0, 0, 0, 0);
		
		tv_top = (TextView) v.findViewById(R.id.tv_top);
		uiAdapter.setTextSize(tv_top, 26);
		
		gridview = (GridView) v.findViewById(R.id.grid_type);

		TypeAdapter typeadapter = new TypeAdapter(mActivity);
		// 添加并且显示
		gridview.setAdapter(typeadapter);
		// 添加消息处理
		gridview.setOnItemClickListener(new ItemClickListener());
	}

	// 当AdapterView被单击(触摸屏或者键盘)，则返回的Item单击事件
	class ItemClickListener implements OnItemClickListener {
		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int position,
				long arg3) {
//			System.out.println(position + "");
			
		}
	}
}
